<template>
	<div ref="tooltipRef" v-show="showPopover" :style="{ left: `${xAxis}px`, top: `${yAxis}px` }" class="customTooltip">
		<div class="pop-wrap">
			<div class="pop-head">
				<div class="head-title">
					<div class="title">
						<b>XXXXXXXXXXXXXX电站</b>
						<span>调度限电</span>
					</div>
					<p>温馨提示：灰损严重：需要清洗喽</p>
				</div>
				<div class="head-button">
					<i></i>
					<span>进入电站</span>
				</div>
			</div>
			<div class="pop-info">
				<div class="item">
					<p><span>装机容量：</span>20MW</p>
					<p><span>日发电量：</span>2550.23万kWh</p>
					<p><span>发电小时：</span>6.51h</p>
					<p><span>健康指数：</span>98.42</p>
					<p><span>总架次：</span>3架<i></i></p>
				</div>
				<div class="item">
					<p><span>并网时间：</span>2023-03-03</p>
					<p><span>上网电量：</span>20.23万kWh</p>
					<p><span>综合效率：</span>98.23%（正常）</p>
					<p><span>健康等级：</span>正常</p>
					<p><span>执飞架次：</span>1架<i></i></p>
				</div>
			</div>
			<div class="pop-map" v-if="showPopover">
				<Echarts :option="echartsOption"></Echarts>
			</div>
		</div>
	</div>
</template>

<script setup>
import Echarts from "@/components/Echarts";
const props = defineProps({
	showPopover: {
		type: Boolean,
		default: false
	},
	isMouseMoved: {
		type: Boolean,
		default: false
	},
	info: {
		type: Object,
		default: () => {
			return {
				collectingLineName: "",
				deviceDetailList: [],
				collectingLineCode: ""
			};
		}
	}
});
const emits = defineEmits(["enter", "leave"]);
const echartsOption = {
	tooltip: {
		trigger: "axis",
		backgroundColor: "rgba(0,0,0,0.8)",
		textStyle: {
			color: "#fff"
		},
		borderColor: "#8BA1BF",
		axisPointer: {
			type: "none"
		}
	},
	legend: {
		show: true,
		top: 10,
		right: 24,
		icon: "circle",
		itemWidth: 8,
		itemHeight: 8,
		textStyle: {
			color: "#8DA3C1"
		}
	},
	grid: [
		{
			left: 46,
			right: 30,
			top: 46,
			bottom: 40
		}
	],
	xAxis: {
		type: "category",
		boundaryGap: false,
		axisTick: {
			show: false
		},
		nameTextStyle: {
			color: "#8DA3C1",
			align: "left",
			padding: [0, 0, 0, 0],
			fontSize: 10.130208333333332
		},
		axisPointer: {
			type: "line",
			lineStyle: {
				color: "#8BA1BF",
				type: "dashed",
				width: 1.0130208333333333
			}
		},
		axisLabel: {
			color: "#8DA3C1",
			fontSize: 12.15625
		},
		axisLine: {
			lineStyle: {
				color: "#0C304C"
			}
		},
		data: ["00:00", "02:00", "04:00", "06:00", "08:00", "10:00", "12:00"]
	},
	yAxis: {
		type: "value",
		name: "万kW",
		nameTextStyle: {
			color: "#8DA3C1",
			align: "right",
			padding: [0, 0, 0, 0],
			fontSize: 12.15625
		},
		axisLabel: {
			formatter: "{value}",
			color: "#8DA3C1",
			fontSize: 12.15625
		},
		splitLine: {
			lineStyle: {
				color: "#0C304C"
			}
		}
	},
	series: [
		{
			name: "实际发电量",
			data: [25, 32, 34, 38, 36, 33, 31],
			type: "line",
			smooth: true,
			showSymbol: false,
			areaStyle: {
				opacity: 0.2
			}
		},
		{
			name: "实际功率",
			data: [22, 18, 19, 23, 29, 33, 36],
			type: "line",
			smooth: true,
			showSymbol: false,
			areaStyle: {
				opacity: 0.2
			}
		}
	]
};
const xAxis = ref(0);
const yAxis = ref(0);
const tooltipRef = ref(null);
const updateMouse = event => {
	const tooltipWidth = tooltipRef.value?.offsetWidth;
	const tooltipHeight = tooltipRef.value?.offsetHeight;
	if (event) {
		// 计算弹窗的位置，确保弹窗不会超出视口
		xAxis.value = Math.min(event.offsetX, window.innerWidth - tooltipWidth);
		yAxis.value = Math.min(event.offsetY, window.innerHeight - tooltipHeight - 20);
	} else {
		// 计算弹窗的位置，确保弹窗不会超出视口
		xAxis.value = Math.min(props.x, window.innerWidth - tooltipWidth);
		yAxis.value = Math.min(props.y, window.innerHeight - tooltipHeight - 20);
	}
};
onMounted(() => {
	tooltipRef.value?.addEventListener("mouseenter", () => {
		emits("enter");
	});
	tooltipRef.value?.addEventListener("mouseleave", () => {
		emits("leave");
	});
});
defineExpose({
	updateMouse
});
</script>

<style scoped lang="scss">
.customTooltip {
	position: absolute;
	min-width: 300px;
	max-width: 600px;
	max-height: 600px;
	padding: 10px;
	box-sizing: border-box;
	border-radius: 5px;
	z-index: 99;
}
.pop-wrap {
	width: 425px;
	height: 432px;
	background: url("@/assets/images/home/pop_bg.png") no-repeat;
	background-size: contain;
	.pop-head {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 24px 20px 14px 22px;
		border-bottom: 1px dashed #164261;
		.head-title {
			.title {
				display: flex;
				align-items: center;
				b {
					font-weight: 800;
					font-size: 18px;
					color: #ffffff;
				}
				span {
					margin-left: 12px;
					width: 60px;
					height: 20px;
					background: rgba(255, 181, 80, 0.2);
					border-radius: 4px;
					border: 1px solid #ffb550;
					font-size: 11px;
					color: #ffb550;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
			p {
				font-size: 14px;
				color: #8da3c1;
			}
		}
		.head-button {
			display: flex;
			align-items: center;
			i {
				width: 16px;
				height: 16px;
				background: url("@/assets/images/home/pop_icon_dz.png") no-repeat;
				background-size: contain;
			}
			span {
				font-weight: 500;
				font-size: 13px;
				color: #50bbff;
				padding-left: 2px;
			}
		}
	}
	.pop-info {
		display: flex;
		padding: 4px 18px 0;
		border-bottom: 1px dashed #164261;
		position: relative;
		&::after {
			content: "";
			position: absolute;
			top: 0;
			left: 48%;
			width: 1px;
			height: 163px;
			background: linear-gradient(to bottom, rgba(80, 187, 255, 0) 0%, rgba(80, 187, 255, 0.2) 48%, rgba(80, 187, 255, 0) 100%);
		}
		.item {
			width: 50%;
			&:last-child {
				padding-left: 16px;
			}
			p {
				padding: 8px 0;
				display: flex;
				align-items: center;
				font-weight: bold;
				font-size: 14px;
				color: #d6eefb;
				line-height: 14px;
				span {
					width: 70px;
					font-weight: 400;
					font-size: 14px;
					color: #8da3c1;
				}
				i {
					width: 24px;
					height: 24px;
					background: url("@/assets/images/home/pop_icon_wrj.png") no-repeat;
					background-size: contain;
					margin-left: 4px;
				}
			}
		}
	}
	.pop-map {
		width: 100%;
		height: 184px;
	}
}
</style>
